<template>
  <div v-if="brand">
    <van-nav-bar
      title="品牌详情"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    >
      <template #right>
        <van-icon name="search" size="22" />
      </template>
    </van-nav-bar>
    <div class="brand">
      <img :src="brand.list_pic_url" alt="" />
      <div class="name">{{ brand.name }}</div>
      <div class="desc">{{ brand.simple_desc }}</div>
    </div>
    <div class="related">
      <h2><span>大家都在看</span></h2>
      <MyProduct
        :goodsList="goodsList"
        :filterCategory="filterCategory"
      ></MyProduct>
    </div>
  </div>
</template>

<script>
import MyProduct from "@/components/MyProduct";
import { getBrandDetail, getBrandGoodsList } from "@/request/api.js";
export default {
  components: {
    MyProduct,
  },
  data() {
    return {
      brand: null,
      goodsList: [],
      filterCategory: [],
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onClickRight() {
      this.$router.push("/home/popup");
    },
  },
  activated() {
    getBrandDetail({
      id: this.$route.query.id,
    }).then((res) => {
      if (res.errno == 0) {
        let { brand } = res.data;
        this.brand = brand;
      }
    });
    //获取品牌下的相关产品
    getBrandGoodsList({
      brandId: this.$route.query.id,
      page: 1,
      size: 1000,
    }).then((res) => {
      if (res.errno == 0) {
        let { filterCategory, goodsList } = res.data;
        this.filterCategory = filterCategory;
        this.goodsList = goodsList;
      }
    });
  },
  created() {},
};
</script>

<style lang="less" scoped>
img {
  width: 100%;
}
div.brand {
  background-color: #fff;
  padding: 20px;
  .name {
    text-align: center;
    height: 50px;
    line-height: 50px;
  }
}
.related {
  padding: 10px;
  background-color: #fff;
  margin-top: 20px;
  h2 {
    width: 180px;
    height: 4px;
    margin: 10px auto 30px;
    text-align: center;
    background-color: #fff;
    border-bottom: 1px solid #333;
    position: relative;
    span {
      display: block;
      width: 90px;
      background-color: red;
      padding: 5px;
      position: absolute;
      top: -8px;
      left: 50%;
      transform: translateX(-50%);
      background-color: #fff;
      font-size: 18px;
    }
  }
  .item {
    display: flex;
    line-height: 20px;
    .l {
      margin-right: 10px;
      color: darkred;
      font-size: 20px;
    }
    .r {
      .question {
        line-height: 24px;
      }
      .answer {
        font-size: 14px;
        color: #777;
      }
    }
  }
}
</style>